package com.wsc.wisdomchina.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.javaBean.ShouLiListBean;

import java.util.List;

public class AiGuoAdapter extends BaseAdapter {

    private Context context;
    private List<ShouLiListBean> messageBeen;
    private LayoutInflater mInflater;

    public AiGuoAdapter(Context context, List<ShouLiListBean> messageBeen) {
        this.context = context;
        this.messageBeen = messageBeen;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return messageBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return messageBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_aiguo, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        bindListItem(holder, position);//控制视图显示数据
        return convertView;
    }

    //控制视图显示数据
    private void bindListItem(ViewHolder holder, int pos) {
        holder.tv_title.setText(messageBeen.get(pos).getTitle());
        holder.tv_street.setText(messageBeen.get(pos).getStreetName());
        String date_time = Tools.timedateyyyy_MM_dd(String.valueOf(messageBeen.get(pos).getCreateDate() / 1000));
        holder.tv_time.setText(date_time);
        if (messageBeen.get(pos).getState() == 0) {
            holder.tv_solve.setText("审核中");
            holder.tv_solve.setTextColor(Color.parseColor("#29D7F2"));
        } else if (messageBeen.get(pos).getState() == 1) {
            holder.tv_solve.setText("待评价");
            holder.tv_solve.setTextColor(Color.parseColor("#15CD1F"));
        }else if (messageBeen.get(pos).getState() == 2) {
            holder.tv_solve.setText("完成");
            holder.tv_solve.setTextColor(Color.parseColor("#15CD1F"));
        }  else if (messageBeen.get(pos).getState() == 3) {
            holder.tv_solve.setText("审核失败");
            holder.tv_solve.setTextColor(Color.parseColor("#FC5812"));
        } else if (messageBeen.get(pos).getState() == -1) {
            holder.tv_solve.setText("已取消");
            holder.tv_solve.setTextColor(Color.parseColor("#FC5812"));
        }
    }

    public class ViewHolder {
        private TextView tv_title;//标题
        private TextView tv_street;//来源
        private TextView tv_time;//时间
        private TextView tv_solve;//图片

        public ViewHolder(View view) {

            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_street = (TextView) view.findViewById(R.id.tv_street);
            tv_time = (TextView) view.findViewById(R.id.tv_time);
            tv_solve = (TextView) view.findViewById(R.id.tv_solve);
        }
    }

}
